'use strict';

module.exports = app => {
  // 引入数据类型
  const { INTEGER, STRING, DATE, ENUM, TEXT } = app.Sequelize;
  // 配置
  const Fava = app.model.define('fava',{
    id: {
      type: INTEGER(20).UNSIGNED,
      primaryKey: true,
      autoIncrement: true
    },
    data: {
      type: TEXT,
      allowNull: false,
      defaultValue: '',
      comment: '内容'
    },
    type: {
      type: ENUM,
      values: ['emoticon', 'text', 'image', 'video', 'audio', 'card'],
      allowNull: false,
      defaultValue: 'text',
      comment: '类型',
    },
    options: {
      type: TEXT,
      allowNull: false,
      defaultValue: '',
      comment: '其他参数'
    },
    user_id: {
      type: INTEGER(20).UNSIGNED,
      allowNull: false,
      comment: '用户id',
      references: {
        model: 'user',
        key: 'id'
      },
      onUpdate: 'restrict', // 更新时操作
      onDelete: 'cascade' // 删除时操作
    },
    created_at: DATE,
    updated_at: DATE
  });

  return Fava
};